<template>
    <div>
        <el-button  style="margin:2px 3px;" size="mini" type="primary" @click="openDialog">AO架次替换</el-button>
        <el-dialog title="AO架次替换" :visible.sync="dialogVisible" width="40%" :before-close="handleClose">
            <ul>
                <li style="list-style: none;"><el-input placeholder="请输入替换后的架次" v-model="startPlaneNo" ></el-input></li>
            </ul>
            <span slot="footer" class="dialog-footer">
                <el-button @click="dialogVisible = false;passwordValue='';">取 消</el-button>
                <el-button type="primary" @click="dialogVisible = false; gzbReplan();passwordValue='';">确 定</el-button>
            </span>
        </el-dialog>
        <el-table ref="receiveTable" size="mini" border :data="resData" highlight-current-row  @current-change="tableCurrentChange" height="500"  >
            <el-table-column type="index" label="序号" width="50" :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="aoCode" sortable label="AO编码" width="200":show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="startPlaneNo" sortable label="起始架次" width="100"  :show-overflow-tooltip="true"> </el-table-column>
            <el-table-column prop="msTaskAoId" sortable label="主键" width="0"  :show-overflow-tooltip="true"> </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNumber"
        :page-sizes="[10,20,50,100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount">
        </el-pagination>
    </div>
</template>
<script>
import request from "@/utils/request.js";
export default {
    name:'WorkUnpackTopTable',
    data(){
        return {
            Aodata:{},
            startPlaneNo:"",
            // 当前页数
            pageNumber: 1,
            // 数据总个数
            totalCount: 0,
            // 当前表格数据
            resData: [],
            currentTableData:{},
            rightTableData:{},//界面右边表格勾选的数据
            // 每页数据个数
            pageSize: 20,
            // 确认列表高亮参数
            stableIndex: 0,
            dialogVisible:false,

        }
    },
    methods:{
         handleClose(){
            this.startPlaneNo = "";
            this.dialogVisible = false;
        },
         openDialog(){
            this.startPlaneNo = "";
            this.dialogVisible = true;
        },
        
        // 表格单选
        tableCurrentChange(val){
            console.log("单选参数",val);
            this.currentTableData = val;
            this.$bus.$emit("replanPackgeSearch",val);
        },
        // 每页数据个数改变
        handleSizeChange(val){
            this.pageSize = val;
            this.$bus.$emit('smStToptablePageSize',this.pageSize);
        },
        // 页数改变
        handleCurrentChange(val) {
            this.pageNumber = val;
            this.$bus.$emit('smStToptablePageNumber',this.pageNumber);
        },
        gzbReplan(){
            if(Object.keys(this.currentTableData).length==0){
                this.$Alert({title: "失败",message: '请至少选择一条记录',type: "error"});
                return ;
            }
            request.post("/replacementAoSortiesRest/aoStartPlaneNo",{"sourceAoMap":this.currentTableData,"startPlaneNo":this.startPlaneNo}).then((res)=>{
                if(res.data.retCode=="200"){
                    this.$Alert({title: "成功", message: res.data.message,type: "success"});
                    //通过父组件调用兄弟组件方法，刷新列表
                    this.$emit("clickBrotherBtn");
                    return ;
                }else{
                    this.$Alert({title: "失败", message: res.data.message,type: "error"});
                    return ;
                }
                    
            })
        }
    },
    mounted() {
        this.$bus.$on('smStTopSearch',(res)=>{
            this.resData = res.data.retData;
            this.totalCount = res.data.totalCount;
        }),
        this.$bus.$on('res',(Aodata)=>{
            console.log("ressss",Aodata.data.retData)
            this.Aodata = Aodata.data.retData
        }),
        this.$bus.$on("rigthTableData",(row)=>{
            
            if(row.length>0){
                this.rightTableData = row[0];
            }
        });
  }
}
</script>
